package com.domel76;

import java.util.ArrayList;

import com.domel76.quickfilm.beans.FilmBean;
import com.domel76.quickfilm.common.Constans;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

public class FilmDetails extends Activity {
	FilmBean filmBean = new FilmBean();

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		SQLiteDatabase baza = null;
		setContentView(R.layout.film_details);
		int filmId = -1;

		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			filmId = extras.getInt("filmId", -1);
		}
		try {

			baza = this.openOrCreateDatabase(Constans.DB_NAME, MODE_PRIVATE, null);
			Cursor cursor = baza.rawQuery("SELECT id, title, details, description FROM Film where id=" + filmId, null);

			if (cursor.moveToFirst()) {
				String title = cursor.getString(cursor.getColumnIndex("title"));
				int id = cursor.getInt(cursor.getColumnIndex("id"));
				String details = cursor.getString(cursor.getColumnIndex("details"));
				String description = cursor.getString(cursor.getColumnIndex("description"));
				filmBean.id = id;
				filmBean.title = title;
				filmBean.all = details;
				filmBean.description = description;
			}
         TextView descriptionTextView = (TextView) findViewById(R.id.description); 
         TextView detailsTextView = (TextView) findViewById(R.id.details);
         descriptionTextView.setText(filmBean.description);
         detailsTextView.setText(filmBean.all);
         
         
		} catch (SQLiteException e) {
			Log.e(getClass().getSimpleName(), "Could not create or Open the database");
		} finally {
			if (baza != null)
				baza.close();
		}
	}
}